/* $Id: UserScoreEntry.java 134 2011-08-27 16:48:38Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.datatypes.scores;

import java.io.Serializable;
import javax.cache.Cache;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import alt.djudge.frontend.server.models.CacheModel;


@PersistenceCapable(detachable="true")
@Inheritance(customStrategy = "complete-table")
public class UserScoreEntry extends AbstractScoreEntry implements Serializable, UserScoreInterface
{

	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	
	@Override
	public Long getId()
	{
		return id;
	}
	
	@Override
	public void setId(Long id)
	{
		this.id = id;
	}
	
	@Persistent
	protected Long userId;
	
	public UserScoreEntry()
	{
		// TODO Auto-generated constructor stub
	}
	
	public UserScoreEntry(Long userId)
	{
		this.setUserId(userId);
	}

	public void setUserId(Long userId)
	{
		this.userId = userId;
	}

	public Long getUserId()
	{
		return userId;
	}

	@Override
	public void clearCacheCustom()
	{
		Cache cache = CacheModel.getStaticCache();
		String keyUser = CacheModel.getUserScoreEntryKey(userId);
		cache.remove(keyUser);
	}
}
